<template>
  <div class="page-container">
    <a-card :bodyStyle="{ padding: '0' }" :bordered="false">
      <!-- 开通-->
      <div
        class="box-wrapper"
        v-if="enterpriseDetail && (enterpriseDetail?.config?.hrhcEtcEnabled || enterpriseDetail?.config?.quantumEtcEnabled)"
      >
        <div class="logo-title-wrapper">
          <span class="title">ETC服务</span>
          <div class="open">已开通</div>
        </div>
        <div class="text">如需关闭ETC服务请联系启程的工作人员 </div>
        <!-- 如果一家ETC服务商都没开的，则同线上，展示开通提示；有一家及以上开通的，页面标题处展示【已开通】标签；
        如果开通一家，则无tab选择切换，默认展示开通的服务商引导页面
        如果开通两家，分两个tab分别展示【好人好车】、【量子】，点击可切换下方内容 -->
        <a-tabs v-model:active-key="activeTabkey" style="width: 100%" type="capsule">
          <a-tab-pane key="1" title="好人好车" v-if="enterpriseDetail?.config?.hrhcEtcEnabled">
            <div class="card-wrapper" v-for="(item, index) in model" :key="index">
              <div class="title">{{ item.title }}</div>
              <div class="content-wrapper border-top" v-if="item.content">
                <div class="topic" v-if="item.topic">{{ item.topic }}</div>
                <div class="content flex-row">
                  <div class="text-wrapper">
                    <div v-for="(el, i) in item.content" :key="i">
                      <div v-if="el.topic" class="flex">
                        <div class="text"> {{ el.topic }}</div>
                        <div class="text-blue">{{ el.password }}</div>
                      </div>
                      <div class="text" v-else>{{ el }}</div>
                    </div>
                  </div>
                  <div class="qrcode" v-if="item.qrcode">
                    <a-image :src="item.qrcode" />
                  </div>
                </div>
              </div>
              <div class="content-wrapper border-top" v-else>
                <div class="content flex-col" v-for="(element, j) in item.topicContent" :key="j">
                  <div class="topic" v-if="element.topic" :class="{ active: j == 0 }">{{ element.topic }}</div>
                  <div class="text-wrapper">
                    <div class="text" v-for="(el, i) in element.content" :key="i">{{ el }}</div>
                  </div>
                </div>
              </div>

              <div class="btn-wrapper border-top" v-if="item.btn">
                <a-button type="primary" @click="goTo(item.url, item.permission)">{{ item.btn }}</a-button>
              </div>
            </div>
          </a-tab-pane>
          <a-tab-pane
            :key="enterpriseDetail?.config?.hrhcEtcEnabled ? '2' : '1'"
            title="量子"
            v-if="enterpriseDetail?.config?.quantumEtcEnabled"
          >
            <div class="card-wrapper" v-for="(item, index) in modelQuantum" :key="index">
              <div class="title">
                {{ item.title }}
                <a-tag color="green" style="margin-left: 6px" v-if="enterpriseDetail.config.quantumAgrConfirm && index == 0">已确认</a-tag>
              </div>
              <div class="content-wrapper border-top" v-if="item.content">
                <div class="topic" v-if="item.topic">{{ item.topic }}</div>
                <div class="content flex-row">
                  <div class="text-wrapper">
                    <div v-for="(el, i) in item.content" :key="i">
                      <div v-if="el.topic" class="flex">
                        <div class="text"> {{ el.topic }}</div>
                        <div class="text-blue">{{ el.password }}</div>
                      </div>
                      <div class="text" v-else>{{ el }}</div>
                    </div>
                  </div>
                  <div class="qrcode" v-if="item.qrcode">
                    <a-image :src="item.qrcode" />
                  </div>
                </div>
              </div>
              <div class="content-wrapper border-top" v-else>
                <div class="content flex-col" v-for="(element, j) in item.topicContent" :key="j">
                  <div class="topic" v-if="element.topic" :class="{ active: j == 0 }">{{ element.topic }}</div>
                  <div class="text-wrapper">
                    <div class="text" v-for="(el, i) in element.content" :key="i">{{ el }}</div>
                  </div>
                </div>
              </div>

              <div class="btn-wrapper border-top" v-if="item.btns.length">
                <a-button
                  type="primary"
                  style="margin-left: 10px"
                  @click="goTo(i.url, i.permission)"
                  v-for="(i, indexs) in item.btns"
                  :key="indexs"
                  >{{ i.btn }}</a-button
                >
              </div>
            </div>
          </a-tab-pane>
        </a-tabs>
      </div>
      <!-- 未开通-->
      <div class="box-wrapper active" v-else>
        <div class="logo-title-wrapper">
          <span class="title">ETC服务</span>
          <div class="close">暂未开通</div>
        </div>
        <div class="text">如需开通ETC服务请联系启程的工作人员 </div>
        <div class="money-wrapper">
          <div class="money">
            <img src="../../../assets/box-money-bg.png" alt="" />
            <div class="msg">
              <div class="money-title">无需充值，无需垫资</div>
              <div class="money-text">让用户自己付通行费</div>
            </div>
          </div>
        </div>
        <div class="money-wrapper">
          <div class="money">
            <img src="../../../assets/box-money-bg-1.png" alt="" />
            <div class="msg">
              <div class="money-title">省心省力，坐等分钱</div>
              <div class="money-text">设备方统一运营管理，按比例分润</div>
            </div>
          </div>
        </div>
      </div>
    </a-card>
  </div>
</template>

<script setup name="Tbox">
  import { ref, onMounted } from 'vue'
  import { useRouter } from 'vue-router'
  import { usePermission } from '@/hooks/usePermission'
  import { Message } from '@arco-design/web-vue'
  import etcPic from '@/assets/etc-code-v1.png'
  import etcPicTest from '@/assets/liangzi-etc-code-test.png'
  import etcPicPro from '@/assets/liangzi-etc-code-pro.png'

  const router = useRouter()

  // 读取商户配置
  import useUserStore from '@/store/modules/user'
  const userStore = useUserStore()

  const activeTabkey = ref('1')

  // 企业信息
  const enterpriseDetail = ref(null)
  let model = ref([])
  let modelQuantum = ref([])
  const getDetailApi = () => {
    userStore.setEpDetail((result) => {
      enterpriseDetail.value = result
      console.log(enterpriseDetail.value)
      model = ref([
        {
          title: '1 - 车辆同步',
          topic: '请您悉知：',
          content: [
            '1、车辆绑定ETC需要在【ETC管理平台】提交备案审核，但有前提；',
            '2、前提是：车辆信息必须先在启程里新增，通过“同步”操作进入到【ETC管理平台】。',
          ],
          btn: '进入【车辆信息同步】',
          url: '/value-added/etc/car-info',
          permission: 'svms:asstes:equipment:car-info',
        },
        {
          title: '2 - 车辆信息备案审核',
          topic: '',
          content: [
            '车辆信息同步后，仅需提交审核和等待，审核通过后即可激活ETC。请注意：车辆同步后会自动帮您提交审核，如无变更，该页面无需操作。',
          ],
          btn: '进入【ETC发行与变更】',
          url: '/value-added/etc/hrhc-car',
          permission: 'svms:asstes:equipment:hrhc-car',
        },
        {
          title: '3 - 登录小程序-进行ETC激活',
          topic: '',
          content: [
            '1.在小程序【爱车钥匙车管】或使用微信扫描右侧二维码，进入ETC激活小程序；',
            {
              topic: '2.员工使用系统提供的固定账号及密码登录，',
              password: '账号：' + enterpriseDetail.value.epName + '｜' + '密码：' + enterpriseDetail.value.epPhoneNo,
            },
            '3.登录成功后，根据步骤引导，完成ETC激活。',
          ],
          btn: '',
          qrcode: etcPic,
        },
        {
          title: '4 - 激活后指引您的用户使用ETC',
          topic: '',
          content: ['1、您的用户可以扫描ETC设备上的二维码进行设备租用；', '2、通行费将由用户支付宝自己支付。'],
          btn: '',
        },
      ])
      modelQuantum = ref([
        {
          title: '1- 资料上传、协议的确认、设备采购',
          topic: '',
          content: [
            '1、协议确认，点击【去确认协议】按钮，访问量子网站，首先完善企业资料，资料完善后进行协议确认，协议确认成功后可进行设备采购。',
            '2、协议确认，只需确认一次即可。协议确认后可点击按钮【去采购设备】按钮进行设备采购。设备采购过程中可在量子官网查看物流等信息。 ',
          ],
          btns: [
            {
              btn: enterpriseDetail.value.config?.quantumAgrConfirm == 1 ? '去采购设备' : '去确认协议',
              url: `/value-added/etc/quantum/${enterpriseDetail.value.config?.quantumAgrConfirm == 1 ? 2 : 1}`,
              permission: 'svms:asstes:equipment:quantum',
            },
          ],
        },
        {
          title: '2 - 车辆同步',
          topic: '',
          content: [
            '请您悉知：',
            '1、车辆绑定ETC需要在【ETC管理平台】提交备案审核，但有前提；',
            '2、前提是：车辆信息必须先在启程里新增，通过“同步”操作进入到【ETC管理平台】。',
          ],
          btns: [
            {
              btn: '进入【车辆信息同步】页',
              url: '/value-added/etc/car-info',
              permission: 'svms:asstes:equipment:car-info',
            },
          ],
        },
        {
          title: '3 - 车辆信息备案审核',
          topic: '',
          content: [
            '车辆信息同步后，仅需提交审核和等待，审核通过后即可激活ETC。请注意：车辆同步后会自动帮您提交审核，如无变更，该页面无需操作。',
            {
              topic: '管理员手机号：',
              password: enterpriseDetail.value.quantumAdminPhone || '',
            },
          ],
          btns: [
            {
              btn: '查看车辆备案进度',
              url: '/value-added/etc/quantum/3',
              permission: 'svms:asstes:equipment:quantum',
            },
          ],
        },
        {
          title: '4 - 安装、激活ETC',
          topic: '',
          content: [
            `1、在小程序【${
              import.meta.env.VITE_ENV == 'production' || import.meta.env.VITE_ENV == 'pre' ? '炬核ETC企业版' : '量子炬核ETC企业版测试版'
            }】或使用微信扫描右侧二维码，进入ETC激活小程序；`,
            '2、员工使用系统提供的固定账号及密码登录，管理员手机号：' + enterpriseDetail.value.quantumAdminPhone || '',
            '3、登录成功后，根据步骤引导，完成ETC激活； ',
            // '4、同样支持量子商户后台激活ETC设备。',
          ],
          btns: [
            // {
            //   btn: '去后台激活ETC',
            //   url: '/value-added/etc/quantum/3',
            //   permission: 'svms:asstes:equipment:quantum',
            // },
          ],
          qrcode: import.meta.env.VITE_ENV == 'production' || import.meta.env.VITE_ENV == 'pre' ? etcPicPro : etcPicTest,
        },
        {
          title: '5 - 激活后指引您的用户使用ETC',
          topic: '',
          content: ['1、您的用户可以扫描ETC设备上的二维码进行设备租用；', '2、通行费将由用户支付宝自己支付。'],
          btns: [],
        },
      ])
    })
  }

  const goTo = (url, permission) => {
    if (url) {
      if (usePermission(permission)) {
        router.push({ path: url })
      } else {
        Message.warning(`您没有访问该页面的权限 `)
      }
    }
  }

  onMounted(() => {
    getDetailApi()
  })
</script>

<style lang="less" scoped>
  .page-container {
    padding-bottom: 0;
    .flex-row {
      display: flex;
      flex-direction: row;
      align-items: center;
    }
    .flex-col {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
    }

    .box-wrapper {
      display: flex;
      justify-content: flex-start;
      flex-direction: column;
      align-items: flex-start;
      width: 100%;
      &.active {
        height: 71vh;
        padding: 74px 0 0 57px;
        background-image: url('../../../assets/box-bg.png') !important;
        background-size: 100% 100%;
      }

      .logo-title-wrapper {
        position: relative;
        .title {
          font-weight: 500;
          font-size: 32px;
          color: #1d2129;
          line-height: 40px;
        }
        .open,
        .close {
          position: absolute;
          top: -2px;
          left: 115px;
          display: flex;
          justify-content: center;
          align-items: center;
          font-weight: 600;
          font-size: 12px;
          color: #ffffff;
          line-height: 12px;
          width: 50px;
          height: 19px;
          background: linear-gradient(222deg, #ff7a66 0%, #ff5b60 100%);
          border-radius: 60px;
        }
        .close {
          color: #919aa5;
          width: 64px;
          background: linear-gradient(222deg, #f2f3f5 0%, #dbdbdb 100%);
        }
      }
      .text {
        font-weight: 400;
        font-size: 14px;
        color: #919aa5;
        line-height: 22px;
        margin: 12px 0 32px 0;
      }
      .money-wrapper {
        .money {
          display: flex;
          align-items: center;
          margin-top: 24px;
          img {
            width: 54px;
            height: 54px;
          }
          .money-title {
            font-weight: 500;
            font-size: 16px;
            color: #1d2129;
            line-height: 22px;
            margin-bottom: 3px;
          }
          .money-text {
            font-weight: 400;
            font-size: 12px;
            color: #919aa5;
            line-height: 22px;
          }
        }
      }
      .card-wrapper {
        margin-bottom: 20px;
        width: 100%;
        .title {
          font-weight: 500;
          font-size: 16px;
          color: #1d2129;
          line-height: 24px;
          padding: 12px 20px;
          background: #f2f3f5;
        }
        .border-top {
          border: 1px solid #e5e6eb;
          border-top: none;
        }
        .content-wrapper {
          padding: 20px;
          background-color: #fff;

          .topic {
            font-weight: 500;
            font-size: 14px;
            color: #1d2129;
            line-height: 22px;
            padding-bottom: 8px;
            padding-top: 20px;
            &.active {
              padding-top: 0 !important;
            }
          }
          .content {
            .qrcode {
              width: 90px;
              height: 90px;
              margin-left: 40px;
              cursor: pointer;
            }
            .text {
              color: #1d2129;
              margin: 0;
            }
            .text-blue {
              color: #1890ff;
            }
          }
        }
        .btn-wrapper {
          padding: 16px 20px;
          text-align: right;
          background-color: #fff;
        }
      }
    }
    :deep(.arco-tabs-nav-tab) {
      justify-content: flex-start;
    }
  }
</style>
